package com.coin.controller;

import com.coin.service.MachineService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by chenhao on 2017/5/18.
 */
@RestController
@RequestMapping("/machine")
public class MachineController {
    private Logger logger= LoggerFactory.getLogger(this.getClass());
    @Resource
    private MachineService machineService;

    @PostMapping("/initMachine")
    public ResponseEntity<Boolean> initMachine(@RequestParam Long machineNumber) {
        try {
            boolean success=false;
            if (machineNumber != null) {
                success = machineService.initMachine(machineNumber);
            }
            return new ResponseEntity<Boolean>(success,HttpStatus.OK);
        } catch (Exception e) {
            logger.error("exception:{}",e);
            return new ResponseEntity<Boolean>(false,HttpStatus.INTERNAL_SERVER_ERROR);
        }

    }
}
